<!DOCTYPE html>
<html>
<head th:include="cultivateWeb/header :: culHeaderCss">

</head>
<link type="text/css" href="/css/cultivateWeb/style/news.css" rel="stylesheet">
<link rel="stylesheet" href="/css/cultivateWeb/style/apply.css">
<body>
<!-- 顶部导航 -->
<header th:include="cultivateWeb/header :: header"></header>
<div style="clear: both"></div>
<div style="background-color: #f7f7f7; ">
    <div style="height: 40px">
        <p style="margin: 0px auto auto 380px; line-height: 40px">当前位置：<a href="/cultivate/homepage">首页</a> > 机构申请</p>
    </div>

    <!--<div style="width: 1200px; margin: auto">
        <span class="title gg" a="0" >培训机构申请</span>
        <span class="title1 gg" a="1">实训机构申请</span>
    </div>-->
    <hr style="margin: auto auto 40px auto  ; width: 1200px"/>

    <!-- 行业信息 -->
    <section id="info" style="margin-left: 30px;">

        <div style="width: 1150px;margin:0 auto;" >
            <form id="formId">
                <!--<form id="formId" action="##" enctype="multipart/form-data" >-->
                <div  class="div_3">
                    <label class="span_1">机构logo：</label>
                    <button type="button" class="btn inp_1" style="margin-top: 20px" id="btnUpload1">
                        <i class="fa fa-cloud"></i>上传图片
                    </button>
                    <input type="text" style="opacity:0;width: 1px;"  id="orgPhoto" name="orgPhoto"/>
                    <!--<span id="test1"></span>-->
                </div>
                <div class="div_3">
                    <img id="zp" style="width:200px" src="">
                </div>
                <div class="div_3">
                    <label class="span_1">站点类型<span style="color: #D52525">*</span>：</label>
                    <select name="roleType" id="roleType" class="form-control inp_1">
                        <option value="">请选择</option>
                        <option value="0">培训机构</option>
                        <option value="3">实习就业单位</option>
                    </select>
                </div>
                <div class="div_3">
                    <label class="span_1">机构类型<span style="color: #D52525">*</span>：</label>
                    <!--<input type="hidden" th:value="${org.type}" id="orgType1" />-->
                    <select name="orgType" id="orgType" class="form-control inp_1">
                        <option value="">请选择</option>
                        <option value="1">机关</option>
                        <option value="0">企业</option>
                        <option value="2">事业单位/学校</option>
                        <option value="3">社会团体</option>
                        <option value="4">其它组织机构</option>
                    </select>
                </div>
                <div class="div_3 px" style="display: none">
                    <label class="span_1">申请负责证书<span style="color: #D52525">*</span>：</label>
                    <input name="profileId" id="profileId" placeholder="请选择申请负责证书" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">机构名称<span style="color: #D52525">*</span>：</label>
                    <input type="text" name="name" id="name" placeholder="请输入机构名称" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">机构代码<span style="color: #D52525">*</span>：</label>
                    <input type="text" name="orgCode" id="orgCode" placeholder="请输入社会信用代码/院校代码"
                           class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">法人代表<span style="color: #D52525">*</span>：</label>
                    <input type="text" id="legalRepresentative" placeholder="请输入法人代表" name="legalRepresentative"
                           class="form-control inp_1"/>
                </div>
                <!--企业申请独有字段-->
                <div class="div_3 company" style="display: none">
                    <label class="span_1">营业范围<span style="color: #D52525">*</span>：</label>
                    <input type="text" id="scopeOfBusiness" placeholder="请输入营业范围" name="scopeOfBusiness"
                           class="form-control inp_1"/>
                    <div style="clear: none"></div>
                </div>
                <div class="div_3 company" style="display: none">
                    <label class="span_1">员工数量<span style="color: #D52525">*</span>：</label>
                    <input type="text" id="staffSize" name="staffSize" placeholder="请输入员工数量"
                           class="form-control inp_1"/>
                </div>
                <div class="div_3 company" style="display: none">
                    <label class="span_1">员工学历层次<span style="color: #D52525">*</span>：</label>
                    <input type="text" id="staffArrangement" placeholder="请输入员工学历层次" name="staffArrangement"
                           class="form-control inp_1"/>
                </div>
                <!--学校申请独有字段-->
                <div class="div_3 school" style="display: none">
                    <label class="span_1">学校性质<span style="color: #D52525">*</span>：</label>
                    <select name="schoolNature" id="schoolNature" class="form-control inp_1">
                        <option value="">请选择</option>
                        <option value="0">中职</option>
                        <option value="1">高职</option>
                        <option value="2">本科</option>
                    </select>
                </div>
                <div class="div_3 school" style="display: none">
                    <label class="span_1">考生数<span style="color: #D52525">*</span>：</label>
                    <input type="text" id="numberOfExaminees" placeholder="请输入考生数" name="numberOfExaminees"
                           class="form-control inp_1"/>
                </div>
                <div class="div_3 school" style="display: none">
                    <label class="span_1">师资力量(200字以内)<span style="color: #D52525">*</span>：</label>
                         <textarea type="text" style="height: 60px"
                              id="teacherResources" name="teacherResources" placeholder="请输入师资力量"
                              class="form-control inp_1"></textarea>
                </div>
                <div class="div_3 px" style="display: none">
                    <label class="span_1">培训工种：</label>
                    <input type="text" id="trainingJobs"  name="trainingJobs" placeholder="请输入培训工种" class="form-control inp_1"/>
                </div>
                <div class="div_3 px" style="display: none">
                    <label class="span_1">培训层次：</label>
                    <input type="text" id="trainingArrangement"  name="trainingArrangement" placeholder="请输入培训层次" class="form-control inp_1"/>
                </div>
                <div class="div_3 px" style="display: none">
                    <label class="span_1">培训人数：</label>
                    <input type="number" id="trainingPerson" name="trainingPerson" value="0" placeholder="请输入培训人数" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">单位/学校地址：<span style="color: #D52525">*</span></label>
                    <textarea type="text" id="address"  name="address" style="height: 60px" placeholder="请输入单位/学校地址" class="form-control inp_1"></textarea>
                </div>
                <div class="div_3">
                    <label class="span_1">所属行业：</label>
                    <input type="text" id="industry" name="industry" placeholder="请输入所属行业" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">机构规模：</label>
                    <input type="text" id="orgSize" name="orgSize" placeholder="请输入机构规模" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">机构特色：</label>
                    <input type="text" id="orgItem" name="orgItem" placeholder="请输入机构特色" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">联系人姓名<span style="color: #D52525">*</span>：</label>
                    <input type="text" id="contacts" name="contacts" placeholder="请输入联系人姓名" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">联系人职务<span style="color: #D52525">*</span>：</label>
                    <input type="text" id="contactsPost" name="contactsPost" placeholder="请输入联系人职务"
                           class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">联系人手机号<span style="color: #D52525">*</span>：</label>
                    <input type="text" id="mobile" name="mobile" placeholder="请输入联系人手机号" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">办公座机号：</label>
                    <input type="text" id="workPhoneNum" name="workPhoneNum" placeholder="请输入办公座机号" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">电子邮箱：</label>
                    <input type="text" id="email" name="email" placeholder="请输入电子邮箱" class="form-control inp_1"/>
                </div>
                <div class="div_3">
                    <label class="span_1">网址：</label>
                    <input type="text" id="url" name="url" placeholder="请输入网址" class="form-control inp_1"/>
                </div>
                <div class="div_3" id="adre1">
                    <label class="span_1">机构所在省份<span style="color: #D52525">*</span>：</label>
<!--                                        <input type="text" id="province" placeholder="企业所在份" name="province"  class="form-control inp_1" />-->
                    <select class="form-control inp_1" id="province" name="province">
                    </select>
                </div>
<!--                <div class="div_3">-->
<!--                    <label class="span_1">附件<span style="color: #D52525">*</span>：</label>-->
<!--                    <button type="button" class="btn inp_1" style="margin-top: 20px" id="btnUpload">-->
<!--                        <i class="fa fa-cloud"></i>上传文件-->
<!--                    </button>-->
<!--                    <input type="text" style="opacity:0;width: 1px;"  id="enclosure" name="enclosure"/>-->
<!--                    <span id="test"></span>-->
<!--                </div>-->
                <!--<div class="div_3" th:each="xz:${consultations}">
                    <label class="span_1">附件模板下载：</label>
                    <label style="height: 50px;float: left;margin: 20px 10px auto auto;font-size: 16px;line-height: 50px;">
                        <a target="_blank" style="color: blue" download th:href="${xz.files}" th:text="${xz.title}"></a>
                    </label>
                </div>-->
                <div class="div_3" style="width:1000px">
                    <label class="span_1">机构介绍(200字以内)：</label>
                    <textarea type="text" maxlength="200" style="width: 800px;height:150px;float: left;margin: 20px auto auto auto;"
                              id="introduce" name="introduce" placeholder="请输入机构介绍"
                              class="form-control inp_1"></textarea>
                </div>
                <div class="div_3">
                    <button class="form-control but_1" id="send" type="submit">提交</button>
                </div>
            </form>
        </div>
        <div style="clear: both"></div>
    </section>
</div>
<!-- footer ------------------------------------------------------- -->
<div class="footer" th:include="cultivateWeb/header :: footer"></div>
<script src="/js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script src="/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/js/plugins/validate/jquery.validate.extend.js"></script>
<script src="/js/layui/layui.js"></script>
<!--<script src="/js/certificateWeb/main.js"></script>-->
<script src="/js/content.js"></script>
<script src="/js/jquery.citys.js"></script>
<script>

    function save() {

        if ($("#roleType").val() == 0){
            var profileId = $("#profileId").val();
            if (profileId == ""){
                alert("请选择证书")
            }else {
                ajaxTokenForm("/cultivate/addOrg","POST", $('#formId').serialize(), function () {
                    setTimeout(function () {
                        location.href = "/cultivate/applyRecord"
                    }, 1000);
                })
            }
        }else {
            ajaxTokenForm("/cultivate/addOrg","POST", $('#formId').serialize(), function () {
                setTimeout(function () {
                    location.href = "/cultivate/applyRecord"
                }, 1000);
            })
        }

    }
    $(function () {

        $('#adre').citys({
            province: $("#province").val(),
            onChange: function (info) {
            }
        }, function (api) {

        });

        ajaxToken("/jzApi/user/selUserDetail", "GET", {}, function (res) {

            if (res.orgId != null){
                ajaxToken("/cultivate/findOrg", "GET", {orgId:res.orgId}, function (r) {
                    console.log("R ==" , r);
                    if (r != null){
                        $('#name').val(r.name);
                        $('#orgCode').val(r.orgCode);
                        $('#name').attr("readonly" , true);
                        $('#orgCode').attr("readonly" , true);
                    }
                })
            }

        });

        $("#roleType").change(function () {
            if ($("#roleType").val() ==  0 && $("#roleType").val() != ""){
                $(".px").css("display" , "block");
            }else {
                $(".px").css("display" , "none");
                $("profileId").val("");
                $("#trainingJobs").val("");
                $("#trainingPerson").val(0);
                $("#trainingArrangement").val("")
            }
        });

        $("#orgType").change(function () {
            if ($(this).val() == 0) {
                $(".company").css("display", "block");
            } else {
                $(".company").css("display", "none");
            }

            if ($(this).val() == 2) {
                $(".school").css("display", "block");
            } else {
                $(".school").css("display", "none");
            }
        });

        $('#adre1').citys({province:"湖南省"});
        validateRule();
        selprofile();
        $('.gg').click(function () {
            if ($(this).attr("a") == 0){
                $("#info").css("display","inline");
                $("#notice").css("display","none");
            }
            if ($(this).attr("a") == 1){
                $("#notice").css("display","inline");
                $("#info").css("display","none");
            }
            $(this).addClass("title");
            $(this).siblings().removeClass("title");
            $(this).siblings().addClass("title1");
        })
    })

    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });

    /*$("#send").click(function () {
        console.log($('#formId').serialize());

    })*/

    //证书下拉框
    function selprofile() {
        $.ajax({
            url: "/jzApi/certificates/selProfileFill",
            success: function (res) {
                $('#profileId').selectPage({
                    showField: 'name',
                    keyField: 'id',
                    data: res.data,
                    multiple: true,
                    searchField: 'name'
                });
            }
        });
    }

    // layui.use('upload', function () {
    //     var upload = layui.upload;
    //     //执行实例
    //     upload.render({
    //         elem: '#btnUpload', //绑定元素
    //         url: '/jzApi/utils/fileImprot', //上传接口
    //         size: 1000,
    //         accept: 'file',
    //         done: function (r) {
    //             $("#enclosure").val(r.data);
    //             $("#test").html(subFileName(r.data));
    //         },
    //         error: function (r) {
    //             layer.msg(r.msg);
    //         }
    //     });
    // });


    layui.use('upload', function () {
        var upload = layui.upload;
        //执行实例
        upload.render({
            elem: '#btnUpload1', //绑定元素
            url: '/jzApi/utils/fileImprot', //上传接口
            size: 1000,
            accept: 'images',
            done: function (r) {
                $("#orgPhoto").val(r.data);
                $("#zp").attr("src",r.data);
            },
            error: function (r) {
                layer.msg(r.msg);
            }
        });
    });

    function validateRule() {
        var icon = "<i style='color: red;font-size: 14px'>";
        var a = '</i>';
        $("#formId").validate({
            rules: {
                roleType: {
                    required: true
                },
                orgType: {
                    required: true
                },
                profileId: {
                    required: true
                },
                name: {
                    required: true
                },
                orgCode: {
                    required: true
                },
                address: {
                    required: true
                },
                legalRepresentative: {
                    required: true
                },
                 introduce: {
                     maxlength:200
                },
                /*trainingJobs:{
                    required:true
                },
                trainingPerson:{
                    required:true
                },
                trainingArrangement:{
                    required:true
                },
                introduce:{
                  required:true
                },*/

                //企业
                scopeOfBusiness: {
                    required: true
                },
                staffSize: {
                    required: true
                },
                staffArrangement: {
                    required: true
                },
                //学校
                schoolNature: {
                    required: true
                },
                numberOfExaminees: {
                    required: true
                },
                teacherResources: {
                    required: true,
                     maxlength:200
                },
                contacts: {
                    required: true
                },
                contactsPost: {
                    required: true
                },
                mobile: {
                    required: true,
                    phoneAndMobile: true
                },
                province: {
                    required: true
                }
                // enclosure: {
                //     required: true
                // }
            },
            messages: {
                roleType: {
                    required: icon + "请选择站点类型" + a
                },
                orgType: {
                    required: icon + "请选择机构类型"+ a
                },
                profileId: {
                    required: icon + "请选择证书"+ a
                },
                name: {
                    required: icon + "请输入机构名称"+ a
                },
                orgCode: {
                    required: icon + "请输入机构代码"+ a
                },
                address: {
                    required: icon + "请输入地址"+ a
                },
                legalRepresentative: {
                    required: icon + "请输入法人代表"+ a
                },
                /*trainingJobs:{
                    required: icon + "请输入培训工种"
                },
                trainingPerson:{
                    required: icon + "请输入培训人数"
                },
                trainingArrangement:{
                    required: icon + "请输入培训层次"
                },
                 introduce:{
                    required:icon + "请输入机构介绍"
                },*/
                //企业
                scopeOfBusiness: {
                    required: icon + "请选择营业范围"+ a
                },
                staffSize: {
                    required: icon + "请输入员工数量"+ a
                },
                staffArrangement: {
                    required: icon + "请输入员工学历层次"+ a
                },

                //学校
                schoolNature: {
                    required: icon + "请选择学校性质"+ a
                },
                numberOfExaminees: {
                    required: icon + "请输入考生数"+ a
                },
                teacherResources: {
                    required: icon + "请输入师资力量"+ a
                },

                contacts: {
                    required: icon + "请输入联系人姓名"+ a
                },
                contactsPost: {
                    required: icon + "请输入联系人职务"+ a
                },
                mobile: {
                    required: icon + "请输入联系人手机号"+ a
                },
                province: {
                    required: icon + "请选择企业所在省份"+ a
                 }
                // enclosure: {
                //     required: icon + "请上传附件"+ a
                // }

            }
        })
    }
//

</script>
</body>
</html>